package com.tarena.lbs.basic.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.dao.repository.impl.AreaRepositoryImpl;
import com.tarena.lbs.basic.pojo.vo.AreaVO;
import com.tarena.lbs.basic.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理区域 地市数据业务的接口类
 */
@Api(tags = "区域数据管理")
@RestController
public class AreaController {
    @Autowired
    private AreaService areaService;


    @ApiOperation(value = "查询省级地区列表")
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> queryProvinces(){
        Integer parentId = 0;
        List<AreaVO> vos = areaService.getChildren(parentId);
        return new Result<>(vos);
    }

    @ApiOperation(value = "查询地市列表")
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> queryChildren(@PathVariable("parentId") Integer parentId){
        List<AreaVO> vos = areaService.getChildren(parentId);
        return new Result<>(vos);
    }

    @ApiOperation(value = "查询地市树")
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree(){
        List<AreaVO> vos = areaService.getTree(null);
        return new Result<>(vos);
    }

    //通过openFeign调用该接口,用于解析省,市,区的id,返回省,市,区名称
    @ApiOperation(value = "查询省,市,区")
    @PostMapping("/admin/basic/area/queryArea")
    public Result<List<String>> queryArea(@RequestBody List<Long> idList){
        List<String> areas = areaService.queryArea(idList);
        return new Result<>(areas);
    }

}
